package org.supda.system.controller.system;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
import org.supda.system.controller.common.BaseController;
import org.supda.system.entity.TResources;
import org.supda.system.service.ResourceService;
import org.supda.system.util.DataTablePageUtil;

/**
 * 
 * @author supda
 * @Date 2017-1-14 上午11:21:15
 * 权限管理
 */
@Controller
@RequestMapping("/permission")
public class PermissoionController extends BaseController{

	@Inject ResourceService resourceService;
	
	@RequestMapping(value = {"/",""}, method=RequestMethod.GET, produces="text/html;charset=utf-8")
	public String list(HttpServletRequest request, Model model){
		//查询出子菜单的所有操作
		//model.addAttribute("res", getOperatorRes());
		model.addAttribute("menuId",getOID());
		return SYSTEM_MANAGEMENT_VIEW_PACKAGE+"permission/permission";
	}
	
	/**
	 * 权限查询
	 * @param request
	 * @return
	 */
	 @RequestMapping(value = "/search",method=RequestMethod.POST, produces="text/html;charset=utf-8")  
	 public @ResponseBody DataTablePageUtil<TResources> showUserInfos(WebRequest request){  

	 	DataTablePageUtil<TResources> dtp = new DataTablePageUtil<TResources>(request); 
	 	//开启Or查询
	 	resourceService.listByDataTable(dtp);
	 	return dtp;  	
	}
	 
	/**
	 * 1.进入添加权限页面 GET:/permission_create
	 */
	 @RequestMapping(value = "/create",method=RequestMethod.GET, produces="text/html;charset=utf-8")  
	 public String createUI(
			 @RequestParam(value="id") Long id,
			 HttpServletRequest request, Model model){  
		 
		 //todo 不允许页面添加资源
		 
		 return SYSTEM_MANAGEMENT_VIEW_PACKAGE+"permission/permission-create";
	}
	 
	 
	 /**
	  * 2.添加权限 POST:/permission_create
	  */
	 @RequestMapping(value = "/create",method=RequestMethod.POST, produces="text/html;charset=utf-8")  
	 public @ResponseBody String create(HttpServletRequest request, Model model){  

		//todo 不允许页面添加资源
		 return RESPONSE_SUCCESS;
	}
	 
	 
	 /**
	  * 3.删除权限 DELETE:/permission_delete?id={id}
	  */
	 @RequestMapping(value = "/delete",method=RequestMethod.POST, produces="text/html;charset=utf-8")  
	 public String delete(
			 @RequestParam(value="id") Long id,
			 HttpServletRequest request, Model model){  

	 	return RESPONSE_SUCCESS;
	}
	 
	 /**
	  * 4.进入修改权限页面 GET:/permission_edit?id={id}
	  */
	 @RequestMapping(value = "/edit",method=RequestMethod.GET, produces="text/html;charset=utf-8")  
	 public String editUI(
			 @RequestParam(value="id") Long id,
			 HttpServletRequest request, Model model){  

	 	return SYSTEM_MANAGEMENT_VIEW_PACKAGE+"permission/permission-edit";
	}
	 
	 
	 /**
	  * 5.修改权限 PUT:/permission_edit?id={id}
	  */
	 @RequestMapping(value = "/edit",method=RequestMethod.POST, produces="text/html;charset=utf-8")  
	 public String edit(
			 @RequestParam(value="id") Long id,
			 HttpServletRequest request, Model model){  

		 return RESPONSE_SUCCESS;
	}
	 
	 /**
	  * 6.锁定权限 PUT:/permission_locked?id={id}
	  */
	 @RequestMapping(value = "/locked",method=RequestMethod.POST, produces="text/html;charset=utf-8")  
	 public String locked(
			 @RequestParam(value="id") Long id,
			 HttpServletRequest request, Model model){  

		return RESPONSE_SUCCESS;
	}
}
